package com.exchange.web.interfaces.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.exchange.common.annotation.Log;
import com.exchange.common.enums.BusinessType;
import com.exchange.interfaces.domain.ExchangeLog;
import com.exchange.interfaces.service.IExchangeLogService;
import com.exchange.common.core.controller.BaseController;
import com.exchange.common.core.page.TableDataInfo;
import com.exchange.common.core.domain.AjaxResult;
import com.exchange.common.utils.poi.ExcelUtil;

/**
 * 数据交换_日志 信息操作处理
 * 
 * @author exchange
 * @date 2019-06-03
 */
@Controller
@RequestMapping("/interfaces/exchangeLog")
public class ExchangeLogController extends BaseController
{
    private String prefix = "interfaces/exchangeLog";
	
	@Autowired
	private IExchangeLogService exchangeLogService;
	
	@RequiresPermissions("interfaces:exchangeLog:view")
	@GetMapping()
	public String exchangeLog()
	{
	    return prefix + "/exchangeLog";
	}
	
	/**
	 * 查询数据交换_日志列表
	 */
	@RequiresPermissions("interfaces:exchangeLog:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(ExchangeLog exchangeLog)
	{
		startPage();
        List<ExchangeLog> list = exchangeLogService.selectExchangeLogList(exchangeLog);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出数据交换_日志列表
	 */
	@RequiresPermissions("interfaces:exchangeLog:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ExchangeLog exchangeLog)
    {
    	List<ExchangeLog> list = exchangeLogService.selectExchangeLogList(exchangeLog);
        ExcelUtil<ExchangeLog> util = new ExcelUtil<ExchangeLog>(ExchangeLog.class);
        return util.exportExcel(list, "exchangeLog");
    }
	
	/**
	 * 新增数据交换_日志
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存数据交换_日志
	 */
	@RequiresPermissions("interfaces:exchangeLog:add")
	@Log(title = "数据交换_日志", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(ExchangeLog exchangeLog)
	{		
		return toAjax(exchangeLogService.insertExchangeLog(exchangeLog));
	}

	/**
	 * 修改数据交换_日志
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Long id, ModelMap mmap)
	{
		ExchangeLog exchangeLog = exchangeLogService.selectExchangeLogById(id);
		mmap.put("exchangeLog", exchangeLog);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存数据交换_日志
	 */
	@RequiresPermissions("interfaces:exchangeLog:edit")
	@Log(title = "数据交换_日志", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(ExchangeLog exchangeLog)
	{		
		return toAjax(exchangeLogService.updateExchangeLog(exchangeLog));
	}
	
	/**
	 * 删除数据交换_日志
	 */
	@RequiresPermissions("interfaces:exchangeLog:remove")
	@Log(title = "数据交换_日志", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(exchangeLogService.deleteExchangeLogByIds(ids));
	}
	
}
